package project;

import java.io.*;
import java.util.*;

public class experiment {
    public static void main(String args[]) {
        File file = new File("Product list.txt");
        Scanner sc = null;
        double sum = 0;
        int count = 0;
        try {
            sc = new Scanner(file);
            sc.useDelimiter("[^0123456789.]+");
            while (sc.hasNext()) {
                try {
                    double price = sc.nextDouble();
                    count++;
                    sum = sum + price;
                    System.out.println(price);
                } catch (InputMismatchException exp) {
                    String t = sc.next();
                }
            }
            System.out.println("平均价格:" + sum / count);

           
            BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
            writer.write("平均价格: " + sum / count + "\n");
            writer.close();
        } catch (Exception exp) {
            System.out.println(exp);
        }
    }
}